<template>
	<view class="social">
		<comHead :title="$t('sjzx.sjzx')" :isLeft="false" :isRight="false" rType="social" :isChat="true" @toTbas="toTbas"></comHead>
		<view class="tabs">
			<view class="item" v-for="(item,index) in arr" @click="changeTabs(index)">
				<text :class="active==index?'on':''">{{item}}</text>
			</view>
		</view>
		<view class="contentBox">
			<view class="searchBox">
				<image src="https://siha.vxmeng.com/static/social/search.png" mode="widthFix"></image>
				<input type="text" :placeholder="$t('sjzx.ss')" v-model="search" @confirm="searchFun"/>
			</view>
			<view class="list" v-if="active==0">
<!-- 				<view class="items">
					<view class="l">
						<image class="img" src="https://siha.vxmeng.com/static/social/message.png" mode="widthFix"></image>
						<view class="text">
							<view class="time">
								<text>{{$t('sjzx.xtxx')}}</text>
								<text>11:12</text>
							</view>
							<view class="slh">君子食无求饱,居无求安,敏于事而慎于言,就有道而正焉,可谓好学也已。</view>
						</view>
					</view>
				</view> -->
				
				<template v-if="qun.length>0">
					<view class="items" v-for="(item,index) in qun" @click="comLink('/pages/social/chat?id='+item.qun_id+'&isQun=2')">
						<view class="l">
							<image class="img" src="http://43.132.125.182:2000/static/social/message.png" mode="aspectFill"></image>
							<view class="text">
								<view class="time">
									<text>{{item.qun_name}}</text>
									<text>{{item.createtime}}</text>
								</view>
								<view class="slh">{{item.type==3?'[视频消息]':item.type==4?'[音频消息]':item.type==2?'[图片消息]':item.type==6?'[文件消息]':item.content}}</view>
							</view>
						</view>
					</view>
				</template>
				<template v-if="friend.length>0">
					<view class="items" v-for="(item,index) in friend" @click="comLink('/pages/social/chat?id='+item.friend_id)">
						<view class="l">
							<image class="img" :src="getImg(item.avatar)" mode="aspectFill"></image>
							<view class="text">
								<view class="time">
									<text>{{item.nickname}}</text>
									<text>{{item.createtime}}</text>
								</view>
								<view class="slh">{{item.type==3?'[视频消息]':item.type==4?'[音频消息]':item.type==2?'[图片消息]':item.type==6?'[文件消息]':item.content}}</view>
							</view>
						</view>
					</view>
				</template>
				<text v-else class="none">暂无消息</text>
			</view>
			
			<view class="list" v-if="active==1">
				<view class="item">
					<view class="l" @click="comLink('/pages/social/newFriend')">
						<image class="img" src="https://siha.vxmeng.com/static/social/newPy.png" mode="widthFix"></image>
						<view class="text">
							<view class="time">
								<text>{{$t('sjzx.xdpy')}}</text>
							</view>
						</view>
					</view>
					<view class="r">
						<image src="https://siha.vxmeng.com/static/social/r.png" mode="widthFix"></image>
					</view>
				</view>
				<view class="item" @click="comLink('/pages/social/myQun')">
					<view class="l">
						<image class="img" src="https://siha.vxmeng.com/static/social/message.png" mode="widthFix"></image>
						<view class="text">
							<view class="time">
								<text>我的群聊</text>
							</view>
						</view>
					</view>
					<view class="r">
						<image src="https://siha.vxmeng.com/static/social/r.png" mode="widthFix"></image>
					</view>
				</view>
				<template v-for="(item,index) in friendList">
					<view class="item" @click="comLink('/pages/social/chat?id='+item.id)">
						<view class="l">
							<image class="img" :src="getImg(item.avatar)" mode="aspectFill"></image>
							<view class="text">
								<view class="time">
									<text>{{item.nickname}}</text>
								</view>
							</view>
						</view>
					</view>
				
				</template>
			</view>
			
			<view class="list" v-if="active==2">
				<template v-for="(item,index) in allUserList">
					<view class="item" @click="comLink('/pages/social/addFriend?id='+item.id)">
						<view class="l">
							<image class="img" :src="getImg(item.avatar)" mode="widthFix"></image>
							<view class="text">
								<view class="time">
									<text>{{item.nickname}}</text>
								</view>
							</view>
						</view>
					</view>
				
				</template>
				
				<text v-if="allUserList.length==0" class="none">暂无内容</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				friend:[],
				qun:[],
				friendList:[],
				allUserList:[],
				arr:['消息',this.$t('sjzx.wdhy'),this.$t('sjzx.tjhy')],
				active:0,
				search: ""
			}
		},
		onShow() {
			this.getFriendList()
			this.getFriend()
			this.intVal = setInterval(()=>{
				this.getFriend()
			},5000)
		},
		methods: {
			searchFun(){
				if(this.active==0){
					this.getFriend()
				}else if(this.active==1){
					this.getFriendList()
				}else{
					this.getAllUserList()
				}
			},
			async getAllUserList() {
				const res = await this.$myRequest({
					url: 'api/lt/getAllUserList',
					data: {
						nickname:this.search,
						page:1,
						page_size: 50
					}
				})
				if (res.code == 1) {
					console.log(res)
					this.allUserList = res.data.list
				}
			},
			async getFriend() {
				const res = await this.$myRequest({
					url: 'api/lt/getFriend',
					data: {
						nickname:this.search
					}
				})
				if (res.code == 1) {
					console.log(res)
					this.friend = res.data.list
					this.qun =  res.data.qun_list
				}
			},
			async getFriendList() {
				const res = await this.$myRequest({
					url: 'api/lt/getFriendList',
					data: {
						nickname:this.search
					}
				})
				if (res.code == 1) {
					console.log(res)
					this.friendList = res.data
				}
			},
			toTbas(){
				this.active=2
			},
			changeTabs(index){
				this.active = index
				this.search = ""
				if(index==2){
					this.getAllUserList()
				}
			}
		}
	}
</script>

<style lang="less" scoped>
	.social {
		display: flex;
		flex-direction: column;
		// align-items: center;
		width: 100%;

		.tabs{
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-bottom: 30rpx;
			.item{
				display: flex;
				align-items: center;
				justify-content: center;
				width: 50%;
				text{
					display: inline-flex;
					color: #D8D8D8;
					font-size: 28rpx;
					border-bottom: 4rpx solid rgba(#000,0);
					padding: 10rpx 0;
					&.on{
						color: #fff;
						// font-size: 32rpx;
						border-bottom: 4rpx solid #D8D8D8;
					}
				}
			}
		}
		.contentBox {
			display: flex;
			flex-direction: column;
			align-items: center;
			width: 670rpx;
			margin-left: 40rpx;
			
			/* #ifdef H5 */
			height: calc(100vh - 350rpx);
			/* #endif */
			.searchBox {
				width: 100%;
				height: 68rpx;
				flex-shrink: 0;
				background: rgba(#767B82, 0.3);
				border-radius: 40rpx;
				display: flex;
				align-items: center;
				padding: 0 30rpx;
				box-sizing: border-box;

				image {
					width: 29rpx;
					margin-right: 20rpx;
				}

				input {
					color: #fff;
					font-size: 28rpx;
				}
			}

			.list {
				width: 100%;
				// padding-bottom: 200rpx;
				height: calc(100vh - 300rpx);
				overflow: auto;
				margin-top: 30rpx;
				.none{
					color: #666;
					font-size: 24rpx;
					display: inline-flex;
					width: 100%;
					align-items: center;
					justify-content: center;
					padding: 100rpx 0;
				}
				.item {
					display: flex;
					align-items: center;
					justify-content: space-between;
					width: 100%;
					padding: 20rpx 0;

					.l {
						display: flex;
						align-items: center;
						width: 65%;
						.img {
							width: 96rpx;
							height: 96rpx;
							border-radius: 50%;
							background: #FAA03E;
							display: flex;
							align-items: center;
							justify-content: center;

							image {
								width: 45rpx;
							}
						}

						.text {
							display: flex;
							flex-direction: column;
							margin-left: 20rpx;

							.time {
								display: flex;
								align-items: center;
								justify-content: space-between;
							}

							text {
								color: #fff;
								font-size: 30rpx;

								&:nth-child(2) {
									font-size: 24rpx;
									color: #999999;
									margin-top: 10rpx;
								}
							}

							.slh {
								font-size: 24rpx;
								color: #999999;
								width: 100%;
								margin-top: 10rpx;
							}
						}
					}

					.r {
						display: flex;
						align-items: center;

						.imgs {
							margin-right: 20rpx;

							image {
								width: 48rpx;
								margin-right: -15rpx;
							}
						}

						>image {
							width: 48rpx;
						}
					}
				}
				.azTit{color: #fff;padding: 20rpx 0;font-size: 28rpx;padding-left: 10rpx;}
				.items {
					display: flex;
					align-items: center;
					justify-content: space-between;
					width: 100%;
					padding: 20rpx 0;

					.l {
						width: 100%;
						display: flex;
						align-items: center;
						justify-content: space-between;

						.img {
							width: 96rpx;
							height: 96rpx;
							border-radius: 50%;
							background: #FAA03E;
							display: flex;
							align-items: center;
							justify-content: center;

							image {
								width: 45rpx;
							}
						}

						.text {
							display: flex;
							flex-direction: column;
							width: calc(100% - 116rpx);

							.time {
								display: flex;
								align-items: center;
								justify-content: space-between;
							}

							text {
								color: #fff;
								font-size: 32rpx;

								&:nth-child(2) {
									font-size: 24rpx;
									color: #999999;
									margin-top: 10rpx;
								}
							}

							.slh {
								font-size: 24rpx;
								color: #999999;
								width: 100%;
								margin-top: 10rpx;
							}
						}
					}
				}
			}
		}
	}
</style>